package com.example.ormlitedemo;
import android.content.Context;
import com.example.ormlitedemo.Pojo.UserInfo;
import com.j256.ormlite.dao.Dao;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class UserDao {
private Dao<UserInfo, Integer> dao;
    public UserDao(Context context) {
        try {
             this.dao = DatabaseHelper.getInstance(context).getDao(UserInfo.class);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
    public void create(UserInfo userInfo){
        try {
             dao.create(userInfo);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
    public void insert(UserInfo userInfo){
        try {
            dao.createIfNotExists(userInfo);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
    public List<UserInfo> select(){
        List<UserInfo> list = new ArrayList<>();
        try {
            list = dao.queryForAll();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return list;
    }
    public void clear(){
        try {
            dao.delete(dao.queryForAll());
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
